package com.example.base.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.base.excetion.GlobalExcetion;
import com.example.base.system.domain.SysLoginRecord;
import com.example.base.system.mapper.SysLoginRecordMapper;
import com.example.base.system.service.SysLoginRecordService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * <p>
 * 登录记录 服务实现类
 * </p>
 *
 * @author xiong
 * @since 2024-02-07
 */
@Service
@Transactional
@CacheConfig(cacheNames = "SysLoginRecordServiceImpl")
public class SysLoginRecordServiceImpl extends ServiceImpl<SysLoginRecordMapper, SysLoginRecord> implements SysLoginRecordService {

    @Cacheable(cacheNames = "sysloginrecord",key = "#id")
    @Override
    public SysLoginRecord getById(Serializable id){
        return super.getById(id);
    }

    @CacheEvict(cacheNames = "sysloginrecord", key = "#id")
    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @CacheEvict(cacheNames = "sysloginrecord", key = "#sysloginrecord.id")
    @Override
    public boolean updateById(SysLoginRecord sysloginrecord) {
        return super.updateById(sysloginrecord);
    }

    @CachePut(cacheNames = "sysloginrecord", key = "#sysloginrecord.id")
    public SysLoginRecord saveSysLoginRecord(SysLoginRecord sysloginrecord) throws GlobalExcetion {
        super.save(sysloginrecord);
        return sysloginrecord;
    }

    @CacheEvict(cacheNames = "sysloginrecord", key = "#sysloginrecord.id")
    public SysLoginRecord updateSysLoginRecordById(SysLoginRecord sysloginrecord) throws GlobalExcetion{
        super.updateById(sysloginrecord);
        return sysloginrecord;
    }
}
